package com.tfjybj.itoo.exam.provider.until;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 商俊帅
 * @date 2022/01/10 11:30
 **/
public class Iterables {

    /**
     * 用于mongodb
     * @param iterable
     * @param <E>
     * @return
     */
    public static <E> List<E> toList(Iterable<E> iterable){
        if (iterable==null){
            return Collections.EMPTY_LIST;
        }
        Iterator<E> iterator = iterable.iterator();
        List<E> res = new LinkedList<>();
        while (iterator.hasNext()){
            res.add(iterator.next());
        }
        return res;
    }
}
